Ext.define('AM.view.CraetJobDetailView', {
		extend: 'Ext.grid.Panel',
		alias : 'widget.craetJobDetailView',
		store : 'CraetJobdetailStore',
		columnLines:true,
//		selModel : Ext.create('Ext.selection.CheckboxModel'), 
		selModel: {
	        injectCheckbox: 0,
	        mode: "SIMPLE"     //"SINGLE"/"SIMPLE"/"MULTI"
//	        checkOnly: true     //只能通过checkbox选择
   		 },
   		selType: "checkboxmodel",
    	dockedItems: [{
        xtype: 'pagingtoolbar',
        dock: 'bottom',
        store : 'CraetJobdetailStore',
        displayInfo: true
        },{
        	dock: 'top',
	        xtype: 'toolbar',
		    items: [ {
				       xtype :'button',
				       text: '评级',
				       icon: 'Ext/restful/images/cog_edit.png',
					   handler:editCraetjobActualcore
			      	},'-',' 查询日期: ', 
			      	{
			        xtype:'datefield',
			        format:'Y-m-d',                    
			        id: 'creatjob_search',            
			        width : 150
			      },'-', {
			            xtype: 'button',
			            text: '搜索',
			            icon : 'Ext/restful/images/find.png',
			            margin: '0 0 0 5',
			            handler: function () {
			                 var searchdate1 = Ext.getCmp('creatjob_search').getValue();
			                 var grid=this.ownerCt.ownerCt;
			                 grid.getStore().on('beforeload', function (store, options) {
			                                    var new_params = { serchdate:Ext.util.Format.date(searchdate1, 'Y-m-d')};
			                                    Ext.apply(store.proxy.extraParams, new_params);
			                                    });
			                 grid.getStore().reload();
			                }
			        }]
	      
        }],
        selType:  'cellmodel',
        plugins: [{
			            ptype: 'rowexpander',
			            rowBodyTpl : new Ext.XTemplate(
			                '<p><b>要求:</b> {jobRequirement}</p>',
			                '<p><b>回复:</b> {huifu}</p><br>' 
			            )
			        },Ext.create('Ext.grid.plugin.CellEditing', {
			            clicksToEdit: 1
			        })],
		columns: [
			        { text: '序号', width:50,align:'center',xtype: 'rownumberer'},
			        { width:0,align:'center',dataIndex: 'id'},
			        { text: '名称', dataIndex: 'name', width:90,align:'center'},
			        { text: '所属项目', dataIndex:'job.name', width:100,align:'center'},
//			        { text: '步骤', dataIndex: 'step', width:50,align:'center'},
//			        { text: '科室',  dataIndex: 'department.name',  width:90,align:'center' },
			        { text: '人员',dataIndex: 'employee.name', width:60,align:'center' },
			        { text: '开始时间', dataIndex: 'startdate', width:100,align:'center',xtype: 'datecolumn',   format:'Y-m-d'},
			        { text: '计划完成时间',  dataIndex: 'planCompleteDate',  width:100,align:'center',xtype: 'datecolumn',   format:'Y-m-d' },
			        { text: '状态',  dataIndex: 'state',  width:70,align:'center',renderer: function(value){
								 if (value === 1) {
										  return '<span style="color:purple;">未办理</span>'; 
								 }if (value ===2) {
										 return '<span style="color:green;">办理中</span>';
								 }if (value ===3) {
										return '<span style="color:red;">结束</span>';
								 }						 
						 }
			        },
			        { text: '办理状态',dataIndex: 'handleState', width:80,align:'center',renderer: function(value){
								 if (value === 1) {
										 return '<span style="color:green;">正常</span>';
								 }if (value ===2) {
										return '<span style="color:red;">延时</span>';
								 }
			       		 }
			        },
			        { text: '得分',dataIndex: 'core', width:60,align:'center',format:'0.00' },
			        { text: '评级', dataIndex: 'pingji', width:80,align:'center',renderer: function(value){
								 if (value === 1.3) {
										 return '<span >优秀</span>';
								}
								 if (value === 1.1) {
										 return '<span >良好</span>';
								}
								 if (value === 1.0) {
										 return '<span >合格</span>';
								}
								 if (value === 0.8) {
										 return '<span >不合格</span>';
								}
						 },
			        	field: {
					        xtype: 'combobox',
			                triggerAction: 'all',
			                queryMode: 'local', 
			                store:"PingJiStore",
			                displayField:'name',
			                valueField:'id'
			              }},
			        { text: '要求', dataIndex: 'jobRequirement', width:120,align:'center'},
			        { text: '回复',  dataIndex: 'huifu',  width:80,align:'center' }
			     ]
	
})
function editCraetjobActualcore(){
		var grid=this.ownerCt.ownerCt;
		var selections = grid.getSelectionModel().getSelection();
			if(selections){
					if(selections.length==0){
							Ext.MessageBox.alert("提示","请检查是否选中所有行！");
							}else{   
									var ids=[]; var pingjis=[]; var cores=[];
									for(var i=0;i<selections.length;i++){
										var record = selections[i];
										pingjis.push(record.get("pingji"));
										ids.push(record.get("id"));
										cores.push(record.get("core"));
									}
							Ext.Ajax.request({
										url : 'jobDetail_editActualcore',
										success : function() {
//										 Ext.getCmp('performanceGridView').getStore().on('beforeload', function (store, options) {
//                                     	  var new_params = {searchValue:Ext.util.Format.date(searchValue, 'Y-m')}
//                                    	  Ext.apply(store.proxy.extraParams, new_params);
//                                  	   });
											Ext.MessageBox.alert("提示", "评价成功！");
											grid.getSelectionModel().deselectAll();
									 		grid.getStore().reload();	
									 		
										},
											failure : function() {
												Ext.MessageBox.alert("提示", "评价未成功！");
											},
											params : {
												    ids:ids,
												    pingjis:pingjis,
												    cores:cores

												}
									});	
							}
					}	
}
	
